import 'package:xrenovation/utils/http.dart';
import 'package:xrenovation/utils/storage.dart';

class UserApi {
  static Future<Map<String, dynamic>?> getCachedUserInfo() async {
    try {
      final data = await Storage.get('user_info');
      if (data is Map) {
        return Map<String, dynamic>.from(data);
      }
      return null;
    } catch (e) {
      return null;
    }
  }

  static Future<Map<String, dynamic>> updateUserInfo() async {
    final res = await Http.get('/user/info');
    if (res.data['code'] == 200 && res.data['data'] != null) {
      // 确保data是Map类型
      final userData = Map<String, dynamic>.from(res.data['data']);
      await Storage.set('user_info', userData);
      return userData;
    }
    return res.data;
  }
}
